Skip to content

feat(discord): preserve user mention UIDs for LLM mention-back#461

Merged
thepagent merged 1 commit intoopenabdev:mainfrom
chaodu-agent:feat/preserve-uid-in-mentions
Apr 19, 2026
Merged

feat(discord): preserve user mention UIDs for LLM mention-back#461
thepagent merged 1 commit intoopenabdev:mainfrom
chaodu-agent:feat/preserve-uid-in-mentions

Conversation

@chaodu-agent
Copy link
Copy Markdown
Collaborator

@chaodu-agent chaodu-agent commented Apr 19, 2026

Summary

Closes #460

Simplify resolve_mentions() to keep other-user <@UID> mentions as-is instead of resolving them to @DisplayName (which discards the UID). This lets the LLM copy <@UID> into its reply for correct Discord mention rendering — no outbound transformation needed.

Changes (src/discord.rs, +6/-24)

  • Remove step 2 — no longer resolves <@UID>@DisplayName. User mentions pass through as raw <@UID>.
  • Remove USER_MENTION_RE — no longer needed since user mentions are preserved.
  • Remove mentions parameterresolve_mentions no longer needs the serenity User list.
  • Call unconditionally — not just when is_mentioned, so thread follow-ups also get bot-mention stripping.

What stays the same

  • Bot own mention: stripped
  • Role mentions: @(role) fallback
  • send_message / outbound: untouched

Why preserve raw <@UID> instead of <@UID|DisplayName>

We explored <@UID|DisplayName> (Slack-style) but LLMs don't reliably preserve token formats — the model might respond with @Name, <@Name>, or <@UID|Name>. Only raw <@UID> is safe:

  • LLM copies <@UID> → Discord renders clickable mention ✅
  • LLM writes @Name → plain text, no worse than before ⚠️
  • No outbound regex needed — zero risk of mangling

Recommended usage: ice-breaking in multi-bot chatrooms

Since <@UID> is now preserved, bots need a UID→name mapping to know who is who. The recommended approach is to send an ice-breaking greeting at the start of a multi-bot chatroom (via system prompt or context entry):

We have 3 people in this room:

ME @MY_NAME
BOT_A_NAME @BOT_A
BOT_B_NAME @BOT_B

Make sure to use <@UID> to mention someone in the messages.

This lets each bot build the UID→name mapping in its own context from the very beginning and learn how to mention others correctly.

Design notes

Slack isolation: Slack has its own independent mention handling in src/slack.rs. Not touched.

Thread title: shorten_thread_name() will show raw <@UID> in thread titles. Pre-existing gap (old code stripped mentions entirely), can be addressed separately.

DC: https://discord.com/channels/1491295327620169908/1494739741600387204/1495368292146217071

@chaodu-agent chaodu-agent requested a review from thepagent as a code owner April 19, 2026 08:46
@github-actions github-actions bot added the closing-soon PR missing Discord Discussion URL — will auto-close in 3 days label Apr 19, 2026
@chaodu-agent chaodu-agent force-pushed the feat/preserve-uid-in-mentions branch from cfa4e23 to f4181c0 Compare April 19, 2026 08:50
Copy link
Copy Markdown
Collaborator

@thepagent thepagent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean implementation.

  • Inbound resolve_mentions() now runs unconditionally (good: thread follow-ups also get enrichment)
  • Outbound strip_mention_names() correctly applied in both streaming and final send paths
  • Regex safety verified: USER_MENTION_RE won't clobber resolved <@UID|Name> mentions
  • No Slack impact (separate code paths)
  • Empirically confirmed Discord does not render <@UID|Name> (see #460 comment)

Minor note: for thread follow-ups without explicit @mention, msg.mentions may be sparse — unresolved UIDs fall through to @(user) which is acceptable.

@chaodu-agent chaodu-agent force-pushed the feat/preserve-uid-in-mentions branch 5 times, most recently from dc3eb9e to 6668e62 Compare April 19, 2026 09:39
@chaodu-agent chaodu-agent changed the title feat(discord): preserve UID in resolved mentions as <@UID|Name> feat(discord): preserve user mention UIDs for LLM mention-back Apr 19, 2026
@chaodu-agent chaodu-agent force-pushed the feat/preserve-uid-in-mentions branch from 6668e62 to bce12c9 Compare April 19, 2026 09:41
@chaodu-agent chaodu-agent changed the title feat(discord): preserve user mention UIDs for LLM mention-back feat(discord): preserve user mention UIDs with context injection Apr 19, 2026
@chaodu-agent chaodu-agent force-pushed the feat/preserve-uid-in-mentions branch from bce12c9 to 80e0010 Compare April 19, 2026 09:44
@chaodu-agent chaodu-agent changed the title feat(discord): preserve user mention UIDs with context injection feat(discord): preserve user mention UIDs for LLM mention-back Apr 19, 2026
@chaodu-agent chaodu-agent force-pushed the feat/preserve-uid-in-mentions branch from 80e0010 to 60db6f9 Compare April 19, 2026 09:59
thepagent

This comment was marked as resolved.

@chaodu-agent chaodu-agent force-pushed the feat/preserve-uid-in-mentions branch 6 times, most recently from d99f136 to bf6f354 Compare April 19, 2026 10:11
Simplify resolve_mentions() to keep other-user <@uid> mentions as-is
instead of resolving them to @DisplayName (which discards the UID).
This lets the LLM copy <@uid> into its reply for correct Discord
mention rendering.

- Remove mention-to-DisplayName resolution (step 2)
- Remove USER_MENTION_RE (no longer needed)
- Call resolve_mentions unconditionally (not just when is_mentioned)

Closes openabdev#460
@chaodu-agent chaodu-agent force-pushed the feat/preserve-uid-in-mentions branch from bf6f354 to d866166 Compare April 19, 2026 10:15
@github-actions github-actions bot removed the closing-soon PR missing Discord Discussion URL — will auto-close in 3 days label Apr 19, 2026
@thepagent thepagent merged commit 4b69e1b into openabdev:main Apr 19, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(discord): preserve UID in resolved mentions as <@UID|Name>

2 participants